package com.zabra.zl.ui.clear.presenter;

import com.zabra.zl.App;
import com.zabra.zl.base.BasePresenter;
import com.zabra.zl.data.ClearBean;
import com.zabra.zl.ui.clear.contract.ClearContract;
import com.zabra.zl.ui.clear.model.ClearModel;
import com.zabra.zl.utils.SharedPreferencesUtil;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class ClearPresenter extends BasePresenter<ClearContract.View> implements ClearContract.Presenter {
    private ClearContract.Model model;
    public ClearPresenter() {
        model=new ClearModel();
    }

    @Override
    public void getData(int orderid) {
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.getData(orderid).enqueue(new Callback<ClearBean>() {
            @Override
            public void onResponse(Call<ClearBean> call, Response<ClearBean> response) {
                mView.hideLoading();
                mView.onSuccess(response.body());
                SharedPreferencesUtil.getInstance(App.context).putSP("token",response.headers().get("token"));
            }

            @Override
            public void onFailure(Call<ClearBean> call, Throwable t) {
                mView.hideLoading();
                mView.onError(t);
            }
        });
    }
}
